home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / glob.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  2KB  |  73 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. '''Filename globbing utility.'''
  5. import os
  6. import fnmatch
  7. import re
  8. __all__ = [
  9.     'glob']
  10.  
  11. def glob(pathname):
  12.     '''Return a list of paths matching a pathname pattern.
  13.  
  14.     The pattern may contain simple shell-style wildcards a la fnmatch.
  15.  
  16.     '''
  17.     if not has_magic(pathname):
  18.         if os.path.lexists(pathname):
  19.             return [
  20.                 pathname]
  21.         else:
  22.             return []
  23.     
  24.     (dirname, basename) = os.path.split(pathname)
  25.     if not dirname:
  26.         return glob1(os.curdir, basename)
  27.     elif has_magic(dirname):
  28.         list = glob(dirname)
  29.     else:
  30.         list = [
  31.             dirname]
  32.     if not has_magic(basename):
  33.         result = []
  34.         for dirname in list:
  35.             if basename or os.path.isdir(dirname):
  36.                 name = os.path.join(dirname, basename)
  37.                 if os.path.lexists(name):
  38.                     result.append(name)
  39.                 
  40.             os.path.lexists(name)
  41.         
  42.     else:
  43.         result = []
  44.         for dirname in list:
  45.             sublist = glob1(dirname, basename)
  46.             for name in sublist:
  47.                 result.append(os.path.join(dirname, name))
  48.             
  49.         
  50.     return result
  51.  
  52.  
  53. def glob1(dirname, pattern):
  54.     if not dirname:
  55.         dirname = os.curdir
  56.     
  57.     
  58.     try:
  59.         names = os.listdir(dirname)
  60.     except os.error:
  61.         return []
  62.  
  63.     if pattern[0] != '.':
  64.         names = filter((lambda x: x[0] != '.'), names)
  65.     
  66.     return fnmatch.filter(names, pattern)
  67.  
  68. magic_check = re.compile('[*?[]')
  69.  
  70. def has_magic(s):
  71.     return magic_check.search(s) is not None
  72.  
  73.